-- 砂流如沼
local shaliuruzhao = fk.CreateSkill {
    name = "mcdh_shaliuruzhao",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

shaliuruzhao:addEffect(fk.CardUsing,{
    can_trigger = function(self, event, target, player, data)
        if player == target or not player:hasSkill(self) then return false end
        if not player:isKongcheng() and not target:isKongcheng() then
            local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
                local use = e.data[1]
                return use.from == target.id
            end, Player.HistoryTurn)
            return #events == 1 and player:getMark("mcdh_charge") >= 3
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        lib.LoseCharge(player, player, 3, self.name)
        local suits_t = target:getTableMark("@mcdh_shaliuruzhao-turn")
        local suits_p = player:getTableMark( "@mcdh_shaliuruzhao-turn")
        local cids = room:askForDiscard(player, 1, 1, false, self.name, false)
        table.insertIfNeed(suits_t, Fk:getCardById(cids[1]):getSuitString(true))
        table.insertIfNeed(suits_p, Fk:getCardById(cids[1]):getSuitString(true))
        if not target:isKongcheng() then
            local cid = room:askForCardChosen(player, target, "h", self.name)
            table.insertIfNeed(suits_t, Fk:getCardById(cid):getSuitString(true))
            table.insertIfNeed(suits_p, Fk:getCardById(cid):getSuitString(true))
            room:throwCard({ cid }, self.name, target, player)
        end
        room:setPlayerMark(target, "@mcdh_shaliuruzhao-turn", suits_t)
        room:setPlayerMark(player, "@mcdh_shaliuruzhao-turn", suits_p)
    end
})

shaliuruzhao:addEffect('prohibit',{
    prohibit_use = function(self, player, card)
        return table.contains(player:getTableMark("@mcdh_shaliuruzhao-turn"), card:getSuitString(true))
    end,
    prohibit_response = function(self, player, card)
        return table.contains(player:getTableMark( "@mcdh_shaliuruzhao-turn"), card:getSuitString(true))
    end,
})

Fk:loadTranslationTable {
    ["mcdh_shaliuruzhao"] = "陷砂",
    [":mcdh_shaliuruzhao"] = "『砂流如沼』<br>蓄力技(3)，一名其他角色在每回合首次使用牌时，你可以弃置你与其各一张手牌，然后本回合你与其不能使用或打出与这些弃置牌同花色的牌。",

    ["#mcdh_shaliuruzhao_prohibit"] = "砂流如沼",
    ["@mcdh_shaliuruzhao-turn"] = "砂流如沼",
}

return shaliuruzhao